<template>
	<div class="edit-box">
		<div class="formula-bar">
			<van-field v-model="disposeCon" :autosize="{ maxHeight: 400 }" label="" type="textarea" placeholder="请输入留言" />
		</div>
		<div class="button-box">
			<div class="finish-button" @click="finshEdit" :class="{ disabled: disposeCon == '' }">完成</div>
		</div>
	</div>
</template>

<script>
import { insertFireDeal, updateFireDeal } from '../../api/fire'
import { Toast } from 'vant'
import dd from 'gdt-jsapi'
export default {
	data() {
		return {
			disposeCon: '',
			fireId: '', // 火点id
			userid: '',
			lastName: '',
			messageid: ''
		}
	},
	mounted() {
		document.title = '火情处置'
		let disposeItem = this.$route.query
		console.log('1212123', disposeItem)
		if (disposeItem.messageid && disposeItem.messageid != '') {
			console.log('进去了')
			this.messageid = disposeItem.messageid
			this.disposeCon = disposeItem.message
		}
		this.fireId = disposeItem.fireId
		this.userid = disposeItem.userid
		this.lastName = disposeItem.lastName
	},
	methods: {
		finshEdit() {
			if (this.disposeCon == '') {
				return
			}
			if (this.messageid) {
				updateFireDeal(this.messageid, this.disposeCon, this.userid, this.lastName).then((res) => {
					console.log(res)
					Toast.success('修改成功')
					setTimeout(() => {
						dd.goBack()
							.then((res) => {
								console.log(res)
							})
							.catch((err) => {
								console.log(err)
							})
					}, 1000)
				})
			} else {
				let formData = new FormData()
				formData.append('message', this.disposeCon)
				formData.append('fireId', this.fireId)
				formData.append('firePersonId', this.userid)
				formData.append('firePerson', this.lastName)
				insertFireDeal(formData).then((res) => {
					console.log(res)
					Toast.success('提交成功')
					setTimeout(() => {
						dd.goBack()
							.then((res) => {
								console.log(res)
							})
							.catch((err) => {
								console.log(err)
							})
					}, 1000)
				})
			}
		}
	}
}
</script>

<style lang="scss">
.edit-box {
	height: 100vh;
	position: relative;
	z-index: 1;
	background: #fff;
	.formula-bar {
		// height: calc(100% - 1.7rem);
		overflow: hidden;
		.van-cell {
			textarea {
				font-size: 0.34rem;
				color: #1f1f1f;
				line-height: 0.5rem;
			}
		}
	}
	.button-box {
		position: absolute;
		bottom: 0.1rem;
		height: 1.24rem;
		width: 100vw;
		padding: 0.18rem 0.32rem;
		border-top: 0.01rem solid rgba(31, 31, 31, 0.09);
		.finish-button {
			width: calc(100% - 0.64rem);
			height: 0.88rem;
			background: #3296fa;
			border-radius: 0.08rem;
			font-size: 0.34rem;
			text-align: center;
			color: #ffffff;
			line-height: 0.88rem;
		}
		.disabled {
			background: rgba(31, 31, 31, 0.17);
		}
	}
}
</style>